#!/usr/bin/env bash
set -Eeo pipefail

USER="$(id -u)"

if [ -z "$(ls -A "/home/nginx/instance")" ]; then
    tar zxf /opt/ngx-template.tar.gz -C /home/nginx/instance/
fi

if [ "$USER" -eq 0 ]; then
    chown -R nginx:nginx /home/nginx/instance/
fi

exec gosu nginx "$@"
